package org.teamh.logic.datamodel;


public class Waypoint {

	private Waypoint next;
	private Waypoint previous;
	private int rotateUnit;
	private float wayToPoint;
	private Cell cell;
	private Map map;
	private String ID;
	private int index;
	
	public Waypoint(String ID) {
		this.ID = ID;
	}
	
	public void setMap(Map map) {
		if(this.map != map) {
			if(getMap() != null) {
				getMap().removeWaypoint(this);
			}
			this.map= map;
			if(getMap() != null) {
				getMap().addWaypoint(this);
			}
		}
	}
	
	public Map getMap() {
		return map;
	}

	public Waypoint getPrevious() {
		return previous;
	}

	public String getID() {
		return ID;
	}

	public void setID(String iD) {
		ID = iD;
	}

	public void setCell(Cell cell) {
		if(this.cell != cell) {
			if(getCell() != null) {
				getCell().removeWaypoint(this);
			}
			this.cell = cell;
			if(getCell() != null) {
				getCell().addWaypoint(this);
			}
		}
	}
	
	public Cell getCell() {
		return cell;
	}
	
	public void setNext(Waypoint next) {
		if(this.next != next) {
			if(getNext() != null) {
				Waypoint oldPrevious = getPrevious();
				this.previous = null;
				oldPrevious.setNext(null);
			}
			this.next = next;
			if(getNext() != null) {
				getNext().setPrevious(this);
			}
		}
	}
	
	public void setPrevious(Waypoint previous) {
		if(this.previous != previous) {
			if(getPrevious() != null) {
				getPrevious().setNext(null);
			}
			this.previous = previous;
			if(getPrevious() != null) {
				getPrevious().setNext(this);
			}
		}
	}
	
	public Waypoint getNext() {
		return next;
	}

	public int getRotateUnit() {
		return rotateUnit;
	}

	public void setRotateUnit(int rotateUnit) {
		this.rotateUnit = rotateUnit;
	}

	public float getWayToPoint() {
		return wayToPoint;
	}

	public void setWayToPoint(float wayToPoint) {
		this.wayToPoint = wayToPoint;
	}

	public float getWorldX() {
		return cell.getWorldX();
	}

	public float getWorldY() {
		return cell.getWorldY();
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getIndex() {
		return index;
	}
}
